﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Xml.Linq;

namespace SilverMap.Editor.Models
{
	public class GridDetail : ModelBase
	{
		private ItemAlignment _alignment = ItemAlignment.TopLeft;
		public ItemAlignment Alignment
		{	
			get { return _alignment; }
			set
			{
				if (value == _alignment)
					return;

				_alignment = value;

				OnPropertyChanged("Alignment");
			}
		}

		private Size _gridSize = new Size(101, 171);
		public Size GridSize
		{	
			get { return _gridSize; }
			set
			{
				if (value == _gridSize)
					return;

				_gridSize = value;

				OnPropertyChanged("GridSize");
			}
		}


		protected override void Load(System.IO.Stream stream)
		{
			var gridDetailsElement = XElement.Load(stream);

			this.GridSize = new Size(gridDetailsElement.GetDoubleValue("width"), gridDetailsElement.GetDoubleValue("height"));
			this.Alignment = (ItemAlignment)Enum.Parse(typeof(ItemAlignment), gridDetailsElement.GetStringValue("alignment"), true);
		}

		protected override void Save(System.IO.Stream stream)
		{
			var gridDetailsElement = new XElement("gridDetails");
			gridDetailsElement.Add(new XAttribute("width", this.GridSize.Width));
			gridDetailsElement.Add(new XAttribute("height", this.GridSize.Height));
			gridDetailsElement.Add(new XAttribute("alignment", this.Alignment.ToString()));

			gridDetailsElement.Save(stream);
		}
	}
}
